<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>导航网站 - 后台登录</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='layui/css/layui.css') }}">
    <style>
        body {
            min-height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            background-size: cover;
            background-position: center;
            position: relative;
        }

        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: -1;
            background-image: url('/static/img/login-bg.png'); /* 替换背景图路径 */
            background-size: cover;
            background-position: center;
            filter: blur(8px);
        }

        .login-box {
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            padding: 30px 40px;
            border-radius: 15px;
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.3);
            width: 100%;
            max-width: 400px;
        }

        .login-title {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            font-size: 24px;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }
    </style>
</head>
<body>
<div class="login-box">
    <div class="login-title">管理员登录</div>
    <form class="layui-form" lay-filter="loginForm">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn layui-btn-fluid" lay-submit lay-filter="loginSubmit">登录
                </button>
            </div>
        </div>
    </form>
</div>

<script src="{{ url_for('static', filename='layui/layui.js') }}"></script>
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        const form = layui.form;
        const layer = layui.layer;
        const $ = layui.jquery;

        form.on('submit(loginSubmit)', function (data) {
            $.ajax({
                url: '/api/auth',
                method: 'POST',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    layer.msg(res.message || '登录成功', {icon: 1, time: 1000}, function () {
                        localStorage.setItem('token', res.token);
                        location.href = '/admin/v2';  // 登录成功跳转
                    });
                },
                error: function (xhr) {
                    const errMsg = xhr.responseJSON?.error || '登录失败';
                    layer.msg(errMsg, {icon: 2});
                }
            });
            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>
